package org.example;


import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.example.openapi.annotation.EnableOpenApi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@EnableOpenApi
@SpringBootApplication
@Slf4j
@EnableFeignClients(basePackages = "org.example.infrastructure.persistence")
@EnableDiscoveryClient
public class UrlShortenerDomainApplication {

    public static void main(String[] args) throws UnknownHostException {
        //关闭nacos的日志配置
        System.setProperty("nacos.logging.default.config.enabled", "false");
        ConfigurableApplicationContext application = SpringApplication.run(UrlShortenerDomainApplication.class, args);
        ConfigurableEnvironment environment = application.getEnvironment();
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        String port = environment.getProperty("server.port");
        String path = environment.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }
        // 打印 swagger 文档地址
        log.info("项目启动启动成功！swagger 接口文档地址: http://" + hostAddress + ":" + port + path + "/swagger-ui/index.html");

    }
}
